import java.awt.Point;


public class Move {
	private Point origin;
	private Point dest;

	public Move(Point origin, Point dest){
		this.origin = origin;
		this.dest = dest;
	}
	
	public Move(int originX, int originY, int destX, int destY){
		origin = new Point(originX, originY);
		dest = new Point(destX, destY);
	}
	
	public Move(String descriptor){
		
		char[] descriptorCharArray = descriptor.toCharArray();
		String filteredDescriptor = "";
		
		for(int i =0; i < descriptor.length(); i++){
			if(descriptorCharArray[i] >= 33 && descriptorCharArray[i] <= 126)
				filteredDescriptor = filteredDescriptor + descriptorCharArray[i];
		}

		String[] squares = filteredDescriptor.split("-");
		origin = stringToSquare(squares[0]);
		dest = stringToSquare(squares[1]);
	}
	
	public Point getOrigin(){
		return origin;
	}
	
	public Point getDest(){
		return dest;
	}
	
	public String toString(){
		return squareToString(origin) + " - " + squareToString(dest);
	}
	
	private String squareToString(Point square){
		//ascii conversion and board inversion
		return (char)(square.x + 65) + "" + (square.y + 1) + "";
	}
	
	private Point stringToSquare(String s){
		int letter = s.toCharArray()[0];
		
		Point p = new Point(letter - 65,  Integer.parseInt(s.substring(1)) - 1);
		return p;
	}
	
	public Move getInverted(){
		return new Move(dest, origin);
	}

}
